﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SecondQuestion
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            int a = 0, b = 0;
            ArrayList nums = new ArrayList();
            try
            {
                a = int.Parse(tb_max.Text);
                b = int.Parse(tb_min.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("!格式错误!");
                tb_max.Text = null;
                tb_min.Text = null;
            }
            if (b >= a || b <= 1)
                MessageBox.Show("！数据错误！");
            for (int i = b; i <= a; i++)
            {
                if (isPrime(i))
                    nums.Add(i);
            }
            string s = "";
            for (int j = 0; j < nums.Count; j++)
            {
                s += nums[j].ToString() + " ";
                if ((j + 1) % 10 == 0)
                    s += "\n" + "\t";
            }
            sum.Text = s;
        }

        private bool isPrime(int num)
        {
            if (num == 2 || num == 3)
                return true;
            for (int j = 2; j < num; j++)
            {
                if (num % j == 0)
                    return false;
            }
            return true;
        }
    }
}
